package com.example.mntz.service.Impl;

import com.example.mntz.dao.UserMapper;
import com.example.mntz.model.Collectionpage;
import com.example.mntz.model.User;
import com.example.mntz.model.UserExample;
import com.example.mntz.model.Yjbd;
import com.example.mntz.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    UserMapper dao;
    @Transactional
    @Override
    public User login(User u) {
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(u.getUsername());
        criteria.andPasswordEqualTo(u.getPassword());
        List<User> user = dao.selectByExample(example);
        dao.updateloginTime(user.get(0).getuId());
        return user.get(0);
    }

    @Override
    public List<Yjbd> selectyjbds(User user ,int top) {
        return dao.selectyjbds(user.getAdmin(),top);
    }

    @Override
    public List<Collectionpage> selectCollectionPage(Integer uid) {
        return dao.selectCollectionPage(uid);
    }

    @Override
    public void insertUser(User user) {
        dao.insertUser(user);
    }
}
